package cn.opopopo.design_pattern_learn.行为型.visitor;

import java.util.Arrays;
import java.util.List;

public class VisitorPatternDemo {
    public static void main(String[] args) {
        List<DocumentElement> document = Arrays.asList(
            new TextElement("Hello World 欢迎来到文档编辑器"),
            new ImageElement("https://example.com/photo.jpg", 1024),
            new TableElement(3, 4),
            new TextElement("这是第二段文字")
        );

        // 导出为 HTML
        HtmlExportVisitor htmlVisitor = new HtmlExportVisitor();
        for (DocumentElement element : document) {
            element.accept(htmlVisitor);
        }
        System.out.println("=== HTML 导出 ===");
        System.out.println(htmlVisitor.getHtml());

        // 统计信息
        WordCountVisitor countVisitor = new WordCountVisitor();
        for (DocumentElement element : document) {
            element.accept(countVisitor);
        }
        System.out.println("=== 统计结果 ===");
        System.out.println("字数: " + countVisitor.getWordCount());
        System.out.println("图片数: " + countVisitor.getImageCount());
        System.out.println("表格数: " + countVisitor.getTableCount());

        // 打印预览
        System.out.println("=== 打印预览 ===");
        PrintPreviewVisitor printVisitor = new PrintPreviewVisitor();
        for (DocumentElement element : document) {
            element.accept(printVisitor);
        }
    }
}